<?php
namespace App\Services\Algo;
use App\Interf\Calculable;
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2016/11/24
 * Time: 15:52
 */

class PsyTestingAlgo extends BaseTestingAlgo implements Calculable{

    protected  $typeFourExpress;

    public function __construct($tid,$answerStr,$typeFourExpress=null)
    {
        parent::__construct($tid,$answerStr);

        $this->typeFourExpress=$typeFourExpress;
    }

    /**R值接口
     * @return int
     */
    public function calculate()
    {
        if($this->typeFourExpress){
            $fourTypeResult = $this->fourTypeArray($this->typeFourExpress,$this->answers);
            foreach($fourTypeResult as $v){
                array_push($this->answers,$v);
            }
        }
        return $this->entrance($this->answers);
    }


    /**将拼装后的答案转换成字符串
     * @return string
     */
    public function resultToStr(){
        return $this->arrToStr($this->answers);
    }


    /**
     * 心里压力算法
     */
    protected function entrance($answers){
        $totalScore = 0;
        foreach ($answers as $answer){
            $totalScore = $totalScore + $answer['weight'];
        }
        return $totalScore;
    }

}